package com.opal.stockTaking.controller;

import com.opal.system.entity.table.PKOrg;
import com.opal.stockTaking.entity.BdStordoc;
import com.opal.stockTaking.entity.StockTakingResult;
import com.opal.stockTaking.form.StockTakignResultForm;
import com.opal.stockTaking.service.StockTakingHelpService;
import com.opal.utils.ResultMsg;
import com.opal.vo.GrfTableVO;
import com.opal.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 盘点管理
 */
@Controller
@RequestMapping("/stockTaking")
public class StockTakingHelpController {

    @Autowired
    private StockTakingHelpService stockTakingHelpService;

    /**
     * 盘点辅助获取组织
     */
    @RequestMapping("/getPKOrgHelp")
    @ResponseBody
    public List<PKOrg> getPKOrg(){
        return stockTakingHelpService.getpkorg();
    }


    /**
     * 获取仓库名称
     * @return
     */
    @RequestMapping("/getBdStordoc")
    @ResponseBody
    public List<BdStordoc> getBdStordoc(){
        return stockTakingHelpService.getBdStordoc();
    }


    /**
     * 获取物料名称
     * @param materialCode
     * @return
     */
    @RequestMapping("/getmaterialName")
    @ResponseBody
    public String getmaterialName(String materialCode){
        return stockTakingHelpService.getmaterialName(materialCode);
    }

    /**
     * 生成票号
     * @return
     */
    @RequestMapping("/stockTakingGenerate")
    @ResponseBody
    public ResultMsg stockTakingGenerate(String date, int startCode , int count){
        return stockTakingHelpService.insertSelective( date,startCode,count);
    }


    /**
     * 查看票号
     * @return
     */
    @RequestMapping("/stockTakingViewCode")
    @ResponseBody
    public List<StockTakingResult> stockTakingViewCode(StockTakingResult stockTakingResult){
        return stockTakingHelpService.selectSelective(stockTakingResult);
    }

    /**
     * 盘点手输更新
     * @param stockTakingResult
     * @return
     */
    @RequestMapping("/stockTakingUpdate")
    @ResponseBody
    public ResultMsg stockTakingUpdate(@RequestBody StockTakingResult stockTakingResult){
        return stockTakingHelpService.updateByPrimaryKeySelective(stockTakingResult);
    }


    /**
     *删除盘点票号
     * @return
     */
    @RequestMapping("/stockTakingDelete")
    @ResponseBody
    public ResultMsg stockTakingDelete(String vbillcode){
        return stockTakingHelpService.deleteByPrimaryKey(vbillcode);
    }


    /**
     * 盘盈亏表生成-合并盘点数据 手工输入与数据库数据
     * @param form
     */
    @RequestMapping("/stockTakingResult")
    @ResponseBody
    public PageVO<StockTakingResult> stockTakingResult(StockTakignResultForm form, @RequestParam("BdStordoc[]") List<String> bdStordoc){
        return stockTakingHelpService.stockTakingResult(form,bdStordoc);
    }


    @RequestMapping("{page}")
    public String skipPage(@PathVariable("page") String page) {
        return "stockTaking/" + page;
    }

}